<template>
  <el-dialog title="添加货品类型" :visible="isShowDialog" @close="btnCancel">
    <!-- 表单 -->
    <el-form ref="form" :model="formData" :rules="rules" label-width="120px">
      <el-form-item label="货品类型编码" prop="data">
        <el-input v-model="formData.code" disabled />
      </el-form-item>
      <el-form-item label="货品类型名称">
        <el-input v-model="formData.name" style="width:88%" placeholder="请输入货品类型名称" />
      </el-form-item>
    </el-form>
    <!-- footer插槽 -->
    <template v-slot:footer>
      <el-row type="flex" justify="center">
        <el-col :span="6">
          <el-button size="small" @click="btnCancel">取消</el-button>
          <el-button type="primary" size="small" @click="btnOK">确定</el-button>
        </el-col>
      </el-row>
    </template>
  </el-dialog>
</template>

<script>
import { addGoodsType } from '@/api/goodstype'

export default {

  props: {
    isShowDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formData: {},
      rules: {
        name: [{ required: true, message: '货品类型名称不能为空', trigger: 'blur' }]
      }
    }
  },
  async created() {
    const num = await addGoodsType()
    console.log(num)
    this.formData.code = num.data.data
    console.log(this.formData.code)
  },
  methods: {
    async btnOK() {
      // 验证表单
      await this.$refs.form.validate()
      // await addGoodsType(this.formData)
      // this.$message.success('添加成功')
      // this.$parent.isShowDialog = false
      // this.$parent.loadPage()
    },
    btnCancel() {
      this.formData = {
        data: '',
        name: ''
      }
      // 清理报错
      this.$refs.form.resetFields()
      // 关闭弹窗
      this.$emit('colseDialog')
    }
  }
}
</script>

<style>

</style>
